import { observe } from "./observe/index";

export function initState(vm) {
    const options = vm.$options;
    if(options.data) {
        initData(vm);
    }
}

function proxy(vm, source, key) {
    Object.defineProperty(vm, key, {
        get() {
            return vm[source][key];
        },
        set(newValue) {
            return vm[source][key] = newValue;
        }
    })
}

function initData(vm) {
    let data = vm.$options.data;
    data = vm._data = typeof data === 'function' ? data.call(vm) : data;
    observe(data);
}